package com.brunogb.pages.server.model;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.users.User;

/**
 * @author jairo
 *
 */
@SuppressWarnings("all")
@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class Profile extends BaseModel {
	
	@PrimaryKey
	@Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
	private Key key;
	
	@Persistent
	private User user;

	/**
	 * 
	 * @param user
	 */
	public Profile(User user) {
		this.user = user;
		if (user != null)
			this.key = KeyFactory.createKey(Profile.class.getSimpleName(), user.getEmail());
		else
			this.key = KeyFactory.createKey(Profile.class.getSimpleName(), "null");
	}

	/**
	 * @return the user
	 */
	public User getUser() {
		return user;
	}

	/**
	 * @param user the user to set
	 */
	public void setUser(User user) {
		this.user = user;
	}
	
	public boolean userIsLoggedIn(){
		return this.user != null;
	}
	
}
